﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CMS_GYM
{
    public partial class frmPhieuThuReportViewer : Form
    {
        #region Attributes
        public clsPhieuThuTienDTO PhieuThu = null;
        #endregion

        #region Contruction
        public frmPhieuThuReportViewer()
        {
            InitializeComponent();
        }

        public frmPhieuThuReportViewer(clsPhieuThuTienDTO _PhieuThu)
        {
            InitializeComponent();
            PhieuThu = _PhieuThu;
        }
        #endregion

        #region events
        private void frmThongTinPhieuChi_Load(object sender, EventArgs e)
        {
            try
            {
                if (PhieuThu!=null)
                {
                    LoadReport();
                }
            }
            catch (Exception Ex) 
            {
                MessageBox.Show("Không lấy được thông tin phiếu thu nên in không thành công! \r\n Nguyên nhân do " + Ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #endregion

        #region functions


        private void LoadReport()
        {
            #region Khai bao bien
            DataTable dtTemp = null;
            DataTable _dtBaoCao = new DataTable();
            #endregion

            #region Thong tin Chi tiet phieu thu

            if (PhieuThu !=null)
            {
                dtTemp =  new clsPhieuThuTienBUS().LayBangPhieuThuChiet(PhieuThu.PhieuThuId);
                if (dtTemp != null && dtTemp.Rows.Count > 0) _dtBaoCao.Merge(dtTemp);
            }

            #endregion

            CMS_GYM.CrystalReports.crpPhieuThu myReport = new CMS_GYM.CrystalReports.crpPhieuThu();
            myReport.SetDatabaseLogon(clsConnection.LoginName, clsConnection.LoginPassword, clsConnection.ServerName, clsConnection.Databasename);
            myReport.SetDataSource(_dtBaoCao);
            myReport.SetParameterValue("SoTienBangChu", hsTool.ConvertMoneyToText(PhieuThu.TongTienThu.ToString()));
            myReport.SetParameterValue("NgayXuat", PhieuThu.NgayXuat.ToString("dd"));
            myReport.SetParameterValue("ThangXuat", PhieuThu.NgayXuat.ToString("MM"));
            myReport.SetParameterValue("NamXuat", PhieuThu.NgayXuat.ToString("yyyy"));
            myReport.SetParameterValue("MaKhachHang", PhieuThu.MaKhachHang);
            myReport.SetParameterValue("HoTen", PhieuThu.HoTen);
            myReport.SetParameterValue("DiaChi", PhieuThu.DiaChi);
            myReport.SetParameterValue("SoPhieuThuIn", PhieuThu.SoPhieuThu);
            myReport.SetParameterValue("KyHieuIn", PhieuThu.KyHieu);
            crystalReportViewer1.ReportSource = myReport;
                

            if (_dtBaoCao == null || _dtBaoCao.Rows.Count < 1)
            {
                MessageBox.Show("Không có dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        #endregion
    }
}
